package interfaz;

import java.awt.image.BufferedImage;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Iterator;

/**
 *
 * @author victor
 */
public class ImageBufferData {

    private BufferedImage buffer;
    private int contador = 0;

    public ImageBufferData() {
    }

    public ImageBufferData(BufferedImage buffer) {
        this.setBuffer(buffer);
    }

    public void setBuffer(BufferedImage buffer) {
        this.buffer = buffer;
    }

    private void increaseCounter() {
        this.contador++;
    }

    public int getCounter() {
        return this.contador;
    }

    public BufferedImage getBuffer() {
        increaseCounter();
        return this.buffer;
    }

    public static String getLeastUsed(HashMap list) {
        String elto;
        String minimo = null;
        int usosMinimos = -1;
        int tmp;
        Iterator it = list.keySet().iterator();

        while (it.hasNext()) {
            elto = (String) it.next();
            if (usosMinimos == -1) {
                minimo = elto;
                usosMinimos = ((ImageBufferData) list.get(elto)).getCounter();
            } else {
                tmp = ((ImageBufferData) list.get(elto)).getCounter();
                if (tmp < usosMinimos) {
                    usosMinimos = tmp;
                    minimo = elto;
                }
            }
        }
        return minimo;
    }
}
